package com.renfei.multimediatask.ui.task8;

import android.media.MediaExtractor;
import android.media.MediaFormat;
import android.util.Log;

import com.renfei.multimediatask.MainActivity;

public class MediaUtil {
    private static final String TAG = MediaUtil.class.getSimpleName();
    private static final boolean VERBOSE = false;

    /**
     * 选择视频通道
     * @param extractor
     * @return
     */
    public static int selectTrack(MediaExtractor extractor) {
        // Select the first video track we find, ignore the rest.
        int numTracks = extractor.getTrackCount();
        for (int i = 0; i < numTracks; i++) {
            MediaFormat format = extractor.getTrackFormat(i);
            String mime = format.getString(MediaFormat.KEY_MIME);
            if (mime.startsWith("video/")) {
                if (VERBOSE) {
                    Log.d(TAG, "Extractor selected track " + i + " (" + mime + "): " + format);
                }
                return i;
            }
        }
        return -1;
    }
}
